<#include "../common/header.htm">
<div class="content-wrapper">
	<section class="content-header">
		<ol class="breadcrumb">
			<li><a href="${ctx}/">首页</a></li>
			<li class="active"><a href="${ctx}/userregister/list">注册用户</a></li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<form action="${ctx}/userregister/list" method="get" id="listForm">
				<div class="box-header">
					<div class="row RowSearchWork">
						<div class="col-sm-2 special-style">
							<label>注册姓名：</label>
							<input type="text" class="form-control" name="registerName" value="${registerName!}" placeholder="请输入注册姓名" />
						</div>
						<div class="col-sm-1">
							<input type="button" class="btn btn-default btn-search" onclick="userregisters.query();" value="查询" />
						</div>
					</div>
				</div>
				<div class="box-body">
					<table class="table table-hover table-bordered table-striped table-hide">
						<thead>
							<tr>
								<th>序号</th>
								<th>注册姓名</th>
								<th>注册电话</th>
								<th>注册时间</th>
								<th>开户公司</th>
								<th>推荐人</th>
								<th>处理状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<#list page.content as u>
								<tr>
									<td>${page.size * page.number + u_index + 1}</td>
									<td>${u.registerName!}</td>
									<td>${u.registerPhone!}</td>
									<td>${u.registerTime?string("yyyy-MM-dd HH:mm:ss")}</td>
									<td>${u.registerCompanyName!}</td>
									<td>${u.inviterName!}</td>
									<td>
										<#if u.dealState?? && dealStateMap?? && dealStateMap["${u.dealState}"]?? >
											${dealStateMap["${u.dealState}"]!}
										</#if>
									</td>
									<td>
										<#if u.registerCompanyId?? >
											<#-- 已开户 -->
											<a href="javascript:void(0)" style="color: #ccc;cursor: default;">处理</a>&nbsp;&nbsp;
											<a href="javascript:void(0)" style="color: #ccc;cursor: default;">开户</a>&nbsp;&nbsp;
										<#else>
											<#-- 未开户 -->
											<a href="javascript:void(0)" onclick="userregisters.deal('${u.registerId}')">处理</a>&nbsp;&nbsp;
											<a href="javascript:void(0)" onclick="userregisters.openAccount('${u.registerId}', '${u.inviteCode!}')">开户</a>&nbsp;&nbsp;
										</#if>
										<a href="javascript:void(0)" onclick="userregisters.dealHistory(${u.registerId})">历史记录</a>
									</td>
								</tr>
							</#list>
						</tbody>
					</table>
					<#include "../common/page.htm">
				</div>
			</form>
		</div>
	</section>
</div>

<script type="text/javascript">
var is_submit=false;

var userregisters = {
	query : function() {
		$(":input[name='pageNumber']").val(0);
		$("form").submit();
	}, 
	deal : function (registerId) {
		if(is_submit){
			return;
		}
		is_submit=true;
		
		var title = "处理";
		var j = 0;
		base.getView({
			url:"${ctx}/userregister/todeal?registerId="+registerId,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						cancel:{
							label:"取消",
							className:"btn btn-secondary",
							callback:function(){
								is_submit=false;
							}
						},
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function() {
								if (j != 0) {
									is_submit=false;
									return ;
								}
								j++;
								base.validAndAjaxSubmit($("#dealForm"), $("#listForm"), function () {
									j = 0;
								});
								return false;
							}
						}
					}
				})
			}
		});
	},
	openAccount : function (registerId, inviterCode) {
		if(is_submit){
			return;
		}
		is_submit=true;
		
		var title = "开户";
		var j = 0;
		base.getView({
			url:"${ctx}/userregister/openaccount?registerId="+registerId+"&inviterCode="+inviterCode,
			success:function(result){
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						cancel:{
							label:"取消",
							className:"btn btn-secondary",
							callback:function(){
								is_submit=false;
							}
						},
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function() {
								if (j != 0) {
									is_submit=false;
									return ;
								}
								j++;
								base.validAndAjaxSubmitJson($("#addCompany"), function () {
									j = 0;
								}, function (response) {
									if (response.result == 'success') {
										$("#listForm").submit();
									} else {
										j = 0;
									}
								});
								return false;
							}
						}
					}
				})
			}
		});
	},
	dealHistory : function (registerId) {
		if(is_submit){
			return;
		}
		is_submit=true;
		
		var title = "历史记录";
		var j = 0;
		base.getView({
			url : "${ctx}/userregister/dealhistory?registerId="+registerId,
			success : function(result) {
				var content = $.trim($(result).html());
				if (content == '') {
					bootbox.alert("暂无历史记录", function() {
						is_submit=false;
					});
					return ;
				}
				bootbox.dialog({
					title:title,
					message:result,
					size:"large",
					closeButton : false,
					buttons:{
						sure:{
							label:"确定",
							className:"btn btn-primary",
							callback:function() {
								is_submit=false;
							}
						}
					}
				})
			}
		});
	}
}
</script>
<#include "../common/footer.htm">